package com.gexiaobao.pigeon.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.gexiaobao.pigeon.R;
import com.gexiaobao.pigeon.app.model.bean.MapLocationBean;

import java.util.List;

/**
 * @Author : hxw
 * @Date : 2024/6/19 11:17
 * @Describe :
 */
public class PoiAdapter extends BaseAdapter {

    private final List<MapLocationBean> poiItemList;
    private final Context context;
    private int selectPosition=0;
    public PoiAdapter(List<MapLocationBean> poiItemList, Context context) {
        this.poiItemList = poiItemList;
        this.context = context;
    }
    @Override
    public int getCount() {
        return poiItemList == null ? 0:poiItemList.size();
    }
    @Override
    public Object getItem(int position) {
        return poiItemList.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_2, parent, false);
            holder = new ViewHolder();
            holder.text1 = convertView.findViewById(android.R.id.text1);
            holder.text2 = convertView.findViewById(android.R.id.text2);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MapLocationBean mapLocationBean =poiItemList.get(position);
        holder.text1.setText(mapLocationBean.name);
        holder.text2.setText(mapLocationBean.address);
        if (selectPosition == position){
            holder.text1.setTextColor(ContextCompat.getColor(context,R.color.green));
            holder.text2.setTextColor(ContextCompat.getColor(context,R.color.green));
        }
        else {
            holder.text1.setTextColor(ContextCompat.getColor(context,R.color.black));
            holder.text2.setTextColor(ContextCompat.getColor(context,R.color.black));
        }
        return convertView;
    }
    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
    }
    static class ViewHolder {
        TextView text1,text2;
    }

}
